<?php
/**
 * 控制器
 *
 * $Id: PortalController.class.php 281 2009-09-29 08:38:27Z sunxy $
 */

require_once(APP_LIB . 'Controller.class.php');

class PortalController extends Controller {

	function __construct() {
		parent::__construct();
		$this->application = 'portal';
	}

	/**
	 * 预处理
	 *
	 * @param array $request
	 */
	function pretreat($request) {

		$p1 = '';
		session_cache_expire(720);
		if (isset($request['sid'])) {
			session_id($request['sid']);
			session_start();
		} else {
			@session_start();
			$request['sid'] = session_id();
		}

		$p1 .= '&amp;sid=' . $request['sid'];
		$this->assign('sid', $request['sid']);
			
		if (!empty($request['tpl'])) {
			$p1 .= '&amp;tpl=' . $request['tpl'];
			$this->assign('tpl', $request['tpl']);
		}

		// parent::assign('p1', $p1);
			
		return parent::pretreat($request);
	}
	
	function execute(&$request) {
	
		parent::execute($request);
		
		$this->_logaccess($request);
	}

	function display($request, $resource_name, $cache_id = null, $compile_id = null) {
		$tpl = $request['tpl'];

		if ($tpl == 'xls') {
			$fmt = "Content-Disposition: attachment; filename=%s.xls";
			header(sprintf($fmt, $request['do']));
		}

		parent::display($request, $resource_name, $cache_id, $compile_id);
	}

	/**
	 * 操作日志
	 *
	 * @param WapControler $controler
	 * @param array $request
	 */
	function _logaccess($request) {
		
		$action = $request['do'];
		if (preg_match("/^(Portal.layout)/i", $action)) {
			return;
		}
		
		require_once(dirname(__FILE__) . '/LogAccess.class.php');
		$aa = new LogAccess();
		
		$aa->_insert($request);
	}
}
?>